#include	<stdio.h>
int findM(int k)
{
    int pos = 0;
    int m = 0;
    int found = 0;
    for(m = (k + 1); ;)
    {
        pos = 0;
        int rest = 2 * k;
        for (;;)
        {
            pos = (pos + m - 1) % rest + 1;
            if (pos <= k)
                break;
            --pos;
            --rest;
        }
        if (rest == k)
        {
            found = 1;
            break;
        }
        if (m % (2 * k) == 0)
            m += k;
        ++m;
    }
    return m;
}

int storeResult[16] = {0x00};
int main(int argc, char *argv[])
{
    int k;
    while (scanf("%d", &k) == 1 && k != 0)
    {
		if (storeResult[k] == 0)
			storeResult[k] = findM(k);
        printf ( "%d\n", storeResult[k]);
    }
    return 0;
}
